﻿using System;
using System.Windows;
using FamilyBook.Core;
using FamilyBook.Core.Configuration;
using FamilyBook.Core.Repositories;
using FamilyBook.Repository.EF;
using FamilyBook.UI.WPF.Modules;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;

namespace FamilyBook.UI.WPF
{
    public class FbBootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return Container.Resolve<FbShell>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();
            
            App.Current.MainWindow = (Window)this.Shell;
            App.Current.MainWindow.Show();
        }

        /*
        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new ModuleCatalog();
        }
        */

        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();
            //((ModuleCatalog)ModuleCatalog).AddModule(typeof(AccountsListModule));

            Type accListModuleType = typeof(AccountsListModule);
            ModuleCatalog.AddModule(new ModuleInfo(accListModuleType.Name, accListModuleType.AssemblyQualifiedName)
                                        {
                                            //ModuleName = accListModuleType.Name,
                                            //ModuleType = accListModuleType.AssemblyQualifiedName,
                                            InitializationMode = InitializationMode.WhenAvailable
                                        });
        }

        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            Container.RegisterType<IConfiguration, AppConfig>(new InjectionConstructor(new InjectionParameter<System.Configuration.Configuration>(null)));
            Container.RegisterType<IDbSession, DbSession>();
            Container.RegisterType(typeof(IGeneralRepository<,>), typeof(GeneralRepository<,>));
        }
    }
}
